package com.zsxb.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zsxb.crm.annotation.AutoFill;
import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.ClueGainDTO;
import com.zsxb.crm.dto.ClueSearchDto;
import com.zsxb.crm.enumeration.OperationType;
import com.zsxb.crm.pojo.Clue;
import com.zsxb.crm.pojo.User;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface ClueMapper extends BaseMapper<Clue> {
    List<Clue> selectByCondition(ClueSearchDto clueSearchDto);

    //Page<Clue> pageQueryPool(CluePoolPageDTO dto);

    Clue getByClueId(Long clueId);

    void gain(ClueGainDTO clueGainDTO);

    //@Log
    @AutoFill(OperationType.INSERT)
    void add(Clue clue);



    Integer getClueNum(User user);

    Integer getClueNum(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateByUserId(Long isUserId, Long outUserId);

    /**
     * 定时任务更新报表数据
     */
    @Select("select count(1) from tb_clue where update_time between #{startOfDay} and #{endOfDay}")
    Integer queryNewClueByDate(LocalDateTime startOfDay, LocalDateTime endOfDay);
    @Select("select count(1) from tb_clue")
    Integer quertAll();
    @Insert("insert into report_statistics (date, new_clue, total_clue) values (#{yesterday}, #{newClue}, #{totalClue})")
    void addClueDataByDate(LocalDate yesterday, Integer newClue, Integer totalClue);

    Integer queryuserfulClueByDate(LocalDateTime startOfDay, LocalDateTime endOfDay);

    @Select("select * from tb_clue")
    List<Clue> findAll();

    @AutoFill(OperationType.UPDATE)
    @Update("update tb_clue set back_reason = #{backReason},status=#{status},remark=#{remark},owner=#{owner},owner_time=#{ownerTime} where id = #{id}")
    void backCluePool(Clue clue);

    List<Clue> selectByClueIds(List<Long> ids);

    Integer countWithUserId(Long userId);
}
